home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 December / Australian PC User - December 2003 (CD2).iso / software / apps / files / dwmx2k4.exe / Disk1 / data1.cab / Configuration_En / DataSources / ColdFusion / CFPARAM.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  6.5 KB  |  271 lines

  1. // Copyright 2001, 2002, 2003 Macromedia, Inc. All rights reserved.
  2.  
  3.  
  4. //*************** GLOBALS VARS *****************
  5.  
  6. var CFPARAM_FILENAME = "REQ_D.gif";
  7. var CFPARAM_LEAF_FILENAME = "DSL_D.gif";
  8.  
  9.  
  10. //******************* API **********************
  11.  
  12.  
  13. //--------------------------------------------------------------------
  14. // FUNCTION:
  15. //   addDynamicSource
  16. //
  17. // DESCRIPTION:
  18. //   Displays the Recordset Server Behavior dialog
  19. //
  20. // ARGUMENTS:
  21. //   none
  22. //
  23. // RETURNS:
  24. //   nothing
  25. //--------------------------------------------------------------------
  26.  
  27. function addDynamicSource()
  28. {
  29.   dw.popupServerBehavior("CFParam.htm");
  30. }
  31.  
  32.  
  33. //--------------------------------------------------------------------
  34. // FUNCTION:
  35. //   findDynamicSource
  36. //
  37. // DESCRIPTION:
  38. //   Called by UD to locate instances of this data source on the page.
  39. //
  40. // ARGUMENTS:
  41. //   none
  42. //
  43. // RETURNS:
  44. //   A list of object with two attributes.  
  45. //   The title to display, and the icon to display.
  46. //--------------------------------------------------------------------
  47.  
  48. function findDynamicSources()
  49. {
  50.   var retList = new Array();
  51.   
  52.   var sbObjs = dwscripts.getServerBehaviorsByFileName("CFParam.htm");
  53.  
  54.   if (sbObjs.length > 0)
  55.   {
  56.     var dataSource = new DataSource(CFPARAM_TITLE, CFPARAM_FILENAME, false, "CFPARAM.htm", "");
  57.     
  58.     retList.push(dataSource);
  59.   }
  60.  
  61.   return retList;
  62. }
  63.  
  64.  
  65. //--------------------------------------------------------------------
  66. // FUNCTION:
  67. //   generateDynamicSourceBindings
  68. //
  69. // DESCRIPTION:
  70. //   Given a one of the title strings returned from findDynamicSource,
  71. //   this function returns the source bindings associated with that
  72. //   Recordset
  73. //
  74. // ARGUMENTS:
  75. //   sourceName - One of the title strings returned in findDynamicSource
  76. //
  77. // RETURNS:
  78. //   Returns a list of bindings for the given elementName
  79. //--------------------------------------------------------------------
  80.  
  81. function generateDynamicSourceBindings(sourceName)
  82. {
  83.   var retList = new Array();
  84.   
  85.   var sbObjs = dwscripts.getServerBehaviorsByFileName("CFParam.htm");
  86.  
  87.   for (var i=0; i < sbObjs.length; i++)
  88.   {
  89.     var dataSource = new DataSource(sbObjs[i].getParameter("ParamName"), CFPARAM_LEAF_FILENAME, true, "CFPARAM.htm", "");
  90.     
  91.     retList.push(dataSource);
  92.   }
  93.  
  94.   return retList;
  95. }
  96.  
  97.  
  98. //--------------------------------------------------------------------
  99. // FUNCTION:
  100. //   generateDynamicDataRef
  101. //
  102. // DESCRIPTION:
  103. //   Returns a dynamic binding string for the given source and binding
  104. //
  105. // ARGUMENTS: 
  106. //   sourceName - the name of a data source
  107. //   bindingName - the name of a binding within that source
  108. //
  109. // RETURNS:
  110. //   Returns a dynamic binding string
  111. //--------------------------------------------------------------------
  112.  
  113. function generateDynamicDataRef(sourceName, bindingName, dropObject)
  114. {
  115.   var retVal = "";
  116.   
  117.   var sbObj = getServerBehaviorByParamName(bindingName);
  118.  
  119.   if (sbObj)
  120.   {
  121.     var paramObj = new Object();
  122.     paramObj.bindingName = bindingName;
  123.  
  124.     retVal = extPart.getInsertString("", "CFParam_DataRef", paramObj);
  125.   }
  126.   
  127.   // We need to strip the cfoutput tags if we are inserting into a CFOUTPUT tag
  128.   // or binding to the attributes of a ColdFusion tag.
  129.   if (dwscripts.canStripCfOutputTags(dropObject, true))
  130.   {
  131.     retVal = dwscripts.stripCFOutputTags(retVal, true);
  132.   } 
  133.  
  134.   return retVal;
  135. }
  136.  
  137.  
  138.  
  139. //--------------------------------------------------------------------
  140. // FUNCTION:
  141. //   inspectDynamicDataRef
  142. //
  143. // DESCRIPTION:
  144. //   Inspects a dynamic binding string and returns a pair of 
  145. //   source and binding names.
  146. //
  147. // ARGUMENTS: 
  148. //   expression - a dynamic binding string
  149. //
  150. // RETURNS:
  151. //   An array of two items.
  152. //   The source name, and the binding name for the given string.
  153. //--------------------------------------------------------------------
  154.  
  155. function inspectDynamicDataRef(expression)
  156. {
  157.   var retVal = new Array();
  158.  
  159.   if (expression.length)
  160.   {    
  161.     var params = extPart.findInString("CFParam_DataRef", expression);
  162.     if (params && params.bindingName)
  163.     {
  164.       // search for params.bindingName within the SBs
  165.       var sbObjs = dwscripts.getServerBehaviorsByFileName("CFParam.htm");
  166.  
  167.       for (var i=0; i < sbObjs.length; i++)
  168.       {
  169.         if (sbObjs[i].getParameter("ParamName").toUpperCase() == params.bindingName.toUpperCase())
  170.         {
  171.           retVal.push(CFPARAM_TITLE);
  172.           retVal.push(params.bindingName);
  173.           break;
  174.         }
  175.       }
  176.  
  177.     }          
  178.   }
  179.   
  180.   return retVal;
  181. }
  182.  
  183.  
  184. //--------------------------------------------------------------------
  185. // FUNCTION:
  186. //   editDynamicSource
  187. //
  188. // DESCRIPTION:
  189. //   edits a dynamic source from the document.
  190. //
  191. // ARGUMENTS:
  192. //   sourceName - a data source name
  193. //   bindingName - one of the bindings for that data source
  194. //
  195. // RETURNS:
  196. //   nothing
  197. //--------------------------------------------------------------------
  198. function editDynamicSource(sourceName, bindingName)
  199. {
  200.   var retVal = false;
  201.   
  202.   var sbObj = getServerBehaviorByParamName(bindingName);
  203.   
  204.   if (sbObj)
  205.   {
  206.       dw.popupServerBehavior(sbObj);
  207.     retVal = true;
  208.   }
  209.   
  210.   return retVal;
  211. }
  212.  
  213.  
  214. //--------------------------------------------------------------------
  215. // FUNCTION:
  216. //   deleteDynamicSource
  217. //
  218. // DESCRIPTION:
  219. //   Deletes a dynamic source from the document.
  220. //
  221. // ARGUMENTS:
  222. //   sourceName - a data source name
  223. //   bindingName - one of the bindings for that data source
  224. //
  225. // RETURNS:
  226. //   nothing
  227. //--------------------------------------------------------------------
  228.  
  229. function deleteDynamicSource(sourceName, bindingName)
  230. {
  231.   var sbObj = getServerBehaviorByParamName(bindingName);
  232.   
  233.   if (sbObj)
  234.   {
  235.     dw.serverBehaviorInspector.deleteServerBehavior(sbObj);
  236.   }
  237. }
  238.  
  239.  
  240. //--------------------------------------------------------------------
  241. // FUNCTION:
  242. //   getServerBehaviorByParamName
  243. //
  244. // DESCRIPTION:
  245. //   Returns the server behavior object that cooresponds to the
  246. //   given cfparam name
  247. //
  248. // ARGUMENTS:
  249. //   paramName - string - the parameter name to locate
  250. //
  251. // RETURNS:
  252. //   server behavior object
  253. //--------------------------------------------------------------------
  254.  
  255. function getServerBehaviorByParamName(paramName)
  256. {
  257.   retVal = null;
  258.   
  259.   var sbObjs = dwscripts.getServerBehaviorsByFileName("CFParam.htm");
  260.   
  261.   for (var i=0; i < sbObjs.length; i++)
  262.   {
  263.     if (sbObjs[i].getParameter("ParamName") == paramName)
  264.     {
  265.       retVal = sbObjs[i];
  266.       break;
  267.     }
  268.   }
  269.   
  270.   return retVal;
  271. }